#!/bin/bash

if command -v apt > /dev/null; then
	sudo apt-get update

	sudo apt-get install -y ca-certificates curl gnupg lsb-release

	# GPG
	sudo mkdir -p /etc/apt/keyrings
	curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

	echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

	# sudo apt-get install -y docker-ce docker-ce-cli containerd.io
	sudo apt-get install -y docker.io
	# 安装Docker Buildx组件
	sudo apt install docker-buildx

else
	sudo yum install -y yum-utils device-mapper-persistent-data lvm2
	sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
	sudo yum install -y docker-ce docker-ce-cli containerd.io

	# todo
fi

sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker

# 将当前用户添加到 docker 用户组
sudo usermod -aG docker $USER
# 重新登录或刷新用户组权限
newgrp docker

sudo cp ./docker_daemon.json /etc/docker/daemon.json

sudo systemctl daemon-reload
sudo systemctl restart docker

